/**
 * @param {number[]} nums1
 * @param {number[]} nums2
 * @return {number[]}
 */
var advantageCount = function (nums1, nums2) {
  nums1.sort((a,b)=>a-b)
  let num = []
  for(let i=0;i<nums2.length;i++){
   let temp =  nums1.find(item=>item>nums2[i])
   if(temp!=undefined){
    num.push(temp)
    nums1.splice(nums1.indexOf(temp),1)
   }
   else {
     num.push(num1[0])
     nums1.splice(0,1)
   }
  }

  return num
}


// [5621,1743,5532,3549,9581],
// [913,9787,4121,5039,1481]
// 8 12 24 32
console.log(advantageCount([5621,1743,5532,3549,9581],
  [913,9787,4121,5039,1481]));